﻿using SLClient.CustomerControls;
using SLClient.ServiceAPI;
using SLClient.ViewModels;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Navigation;

namespace SLClient.Views
{
    public partial class ProfitListView : Page
    {
        private List<NavUserInfo> list;
        private int pos;
        private int pos1;

        public ProfitListView()
        {
            this.InitializeComponent();
            base.DataContext = new ProfitListViewModel();
            this.list = new List<NavUserInfo>();
            this.navControl.SetNavigation(this.list);
        }

        private void btRefreshList_Click(object sender, RoutedEventArgs e)
        {
            (base.DataContext as ProfitListViewModel).RefreshList(ref this.pos, ref this.list);
        }

        private void btRefreshRecord_Click(object sender, RoutedEventArgs e)
        {
            (base.DataContext as ProfitListViewModel).RefreshRecord(ref this.pos1, ref this.list);
        }

        private void btSearchList_Click(object sender, RoutedEventArgs e)
        {
            (base.DataContext as ProfitListViewModel).SearchList(ref this.pos);
        }

        private void btSelect_Click(object sender, RoutedEventArgs e)
        {
            (base.DataContext as ProfitListViewModel).Search(ref this.pos, ref this.pos1, ref this.list);
        }

        private void dgList_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            ViwProfitReport report = e.Row.DataContext as ViwProfitReport;
            if (report.UserId != Guid.Empty)
            {
                int num = ++this.pos;
                (this.dgList.Columns[0].GetCellContent(e.Row) as TextBlock).Text=num.ToString();
            }
        }

        private void dgRecord_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            ProfitList list = e.Row.DataContext as ProfitList;
            if (list.UserId != Guid.Empty)
            {
                int num = ++this.pos1;
                (this.dgRecord.Columns[0].GetCellContent(e.Row) as TextBlock).Text = num.ToString();
            }
        }

        private void navControl_LowerClicked(object sender, NavUserInfo nui)
        {
            (base.DataContext as ProfitListViewModel).GetChildLowerList(nui.UserId, ref this.pos, ref this.list);
            if (this.rbtDetails.IsChecked == true)
            {
                this.rbtLists.IsChecked = true;
                this.rbtDetails.IsChecked = false;
                (base.DataContext as ProfitListViewModel).NavClick(ref this.list);
            }
            this.navControl.SetNavigation(this.list);
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void rbtDetails_Click(object sender, RoutedEventArgs e)
        {
            this.rbtLists.IsChecked = false;
            (base.DataContext as ProfitListViewModel).Transition(ref this.list);
            this.navControl.SetNavigation(this.list);
        }

        private void rbtLists_Click(object sender, RoutedEventArgs e)
        {
            this.rbtDetails.IsChecked = true;
            (base.DataContext as ProfitListViewModel).Transition(ref this.list);
            this.navControl.SetNavigation(this.list);
        }

        private void showOrder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            (base.DataContext as ProfitListViewModel).ShowOrder(ref this.pos1, ref this.list);
        }

        private void TextBlock_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            (base.DataContext as ProfitListViewModel).GetChildLowerList(Guid.Empty, ref this.pos, ref this.list);
            this.navControl.SetNavigation(this.list);
        }

        private void txtSearch_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            this.rbtLists.IsChecked = false;
            this.rbtDetails.IsChecked = true;
            (base.DataContext as ProfitListViewModel).InitDetailes(ref this.pos, ref this.pos1, ref this.list);
            this.navControl.SetNavigation(this.list);
        }

    }
}
